package com.hz.web.controller.front;

import com.hz.web.entity.CkHtmlEntity;
import com.hz.web.entity.vo.DetailResponseVo;
import com.hz.web.entity.vo.IndexResponseVo;
import com.hz.web.service.IckHtmlService;
import com.hz.web.service.IlinkService;
import com.hz.web.util.DateUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("front")
public class DetailController extends BasicController{

    @Resource
    private IckHtmlService ckHtmlService;


    /**
     * 相关的文章详情页信息
     * @param session
     * @param id
     * @return
     */
    @RequestMapping("detail")
    @ResponseBody
    public DetailResponseVo index(HttpSession session, int id) {
        DetailResponseVo detailResponseVo = new DetailResponseVo();

        CkHtmlEntity ckHtmlEntity = ckHtmlService.selectByPrimaryKey(id);
        if(ckHtmlEntity == null){
            detailResponseVo.setSuccess(false);
            return detailResponseVo;
        }


        detailResponseVo.setTitle(ckHtmlEntity.getTitle());
        detailResponseVo.setOperator(ckHtmlEntity.getCreateUser());
        detailResponseVo.setOperatetime(DateUtil.dateToStr(ckHtmlEntity.getCreateTime(), "yyyy-MM-dd"));
        detailResponseVo.setCont(ckHtmlEntity.getHtml());
        return detailResponseVo;
    }

}
